Fix formula cached-value typing and add typed formula result setters#309
Merged
MathNya merged 2 commits intoMathNya:masterfrom Feb 25, 2026
Merged
Conversation
Make formula cell XML type emission follow cached raw value kinds instead of forcing t="str". Also fix error serialization to emit the actual cached error token (for example #N/A) rather than hard-coding #VALUE!. Add unit and integration coverage for typed formula cache writeback, roundtrip semantics, and shared-formula metadata stability.
Add explicit helpers to set formula cached values as number, bool, error, string, or blank without removing the formula object. Expose these helpers on both CellValue and Cell, and add regression coverage for API behavior and XML output typing.
Owner
|
@PSU3D0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR improves formula cached-value writeback correctness and adds explicit APIs for typed cached results.
It is intentionally split into two commits:
Motivation
This work is grounded in a concrete downstream integration need from Formualizer.
Formualizer recently added Rust-native workbook recalculation/writeback (
recalculate_file) usingumya-spreadsheetas the writer path. During validation, formula cached values written back to XLSX were observed as string-typed payloads in XML (t="str") even when the computed result was numeric, boolean, or error.That behavior creates type drift in
sheet*.xmland can degrade interoperability with Excel/OpenXML consumers that rely on correct cached value typing.Additionally, Formualizer needed an explicit, type-safe way to set formula cached results (number/bool/error/string/blank) while preserving formula metadata.
While this was identified through Formualizer, the fix is broadly useful: it improves formula-cache correctness for all
umya-spreadsheetusers.What changed
1) Typed formula cached-value serialization
t="str")t="b"+1/0t="e"+ actual error tokent="str"#N/A) instead of hardcoding#VALUE!.2) New typed API helpers (backwards-compatible)
Added on both
CellValueandCell:set_formula_result_number(...)set_formula_result_bool(...)set_formula_result_error(...)set_formula_result_string(...)set_formula_result_blank()These methods update cached value (
<v>) without removing formula metadata (<f>).Existing
set_formula_result_default(...)remains unchanged.Tests
Added regression coverage for:
Commands run
cargo test(full suite) ✅Backwards compatibility
Why this helps